/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.component.mail.service;

import info.peigen.hotpot.common.service.base.processor.ProcessorServiceContext;
import info.peigen.hotpot.common.service.base.processor.ProcessorServiceInvoke;
import info.peigen.hotpot.component.mail.service.order.MimeMailOrder;
import info.peigen.hotpot.component.mail.service.order.SimpleMailOrder;
import info.peigen.hotpot.component.mail.service.result.MailResult;
import org.noear.solon.annotation.Component;

/**
 * <b>(MailService)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2022/11/16
 */
@SuppressWarnings("rawtypes")
@Component
public class MailService extends AbstractMailService {
    public void sendSimpleMail(SimpleMailOrder order) {
        ProcessorServiceContext serviceContext = ProcessorServiceContext.builder().order(order).result(new MailResult())
                .build();

        execute(serviceContext, new ProcessorServiceInvoke() {
            @Override
            public void addProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(generateMailDomainProcessor, sendSimpleMailProcessor);
            }

            @Override
            public void addPostProcessor(ProcessorServiceContext serviceContext) {
                ProcessorServiceInvoke.super.addPostProcessor(serviceContext);
                serviceContext.addProcessors(sendMailResultProcessor);
            }
        });

    }

    public void sendMimeMail(MimeMailOrder order) {
        ProcessorServiceContext serviceContext = ProcessorServiceContext.builder().order(order).result(new MailResult())
                .build();

        execute(serviceContext, new ProcessorServiceInvoke() {
            @Override
            public void addProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(generateMailDomainProcessor, sendMimeMailProcessor);
            }

            @Override
            public void addPostProcessor(ProcessorServiceContext serviceContext) {
                ProcessorServiceInvoke.super.addPostProcessor(serviceContext);
                serviceContext.addProcessors(sendMailResultProcessor);
            }
        });

    }
}